<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="${mapperpackagename}.${javaname}Mapper" >
    <resultMap id="BaseResultMap" type="${entitypackagename}.${javaname}" >
        <#list tableEntity.columnEntitys as res>
            <#if res.COLUMN_KEY=true>
                <id column="${res.COLUMN_NAME}" property="${tabname_javaname_map[res.COLUMN_NAME]}"  />
            <#else >
            <result column="${res.COLUMN_NAME}" property="${tabname_javaname_map[res.COLUMN_NAME]}" />
            </#if>

        </#list>
    </resultMap>
    ${r'
    <sql id="Example_Where_Clause" >
        <where >
            <foreach collection="oredCriteria" item="criteria" separator="or" >
                <if test="criteria.valid" >
                    <trim prefix="(" suffix=")" prefixOverrides="and" >
                        <foreach collection="criteria.criteria" item="criterion" >
                            <choose >
                                <when test="criterion.noValue" >
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue" >
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue" >
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue" >
                                    and ${criterion.condition}
                                    <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                                    #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    '}
${r'
    <sql id="Update_By_Example_Where_Clause" >
        <where >
            <foreach collection="example.oredCriteria" item="criteria" separator="or" >
                <if test="criteria.valid" >
                    <trim prefix="(" suffix=")" prefixOverrides="and" >
                        <foreach collection="criteria.criteria" item="criterion" >
                            <choose >
                                <when test="criterion.noValue" >
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue" >
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue" >
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue" >
                                    and ${criterion.condition}
                                    <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                                    #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
     '}
    <sql id="Base_Column_List" >
        <#list  tableEntity.columnEntitys as res>${res.COLUMN_NAME}<#if res_has_next = false><#else>,</#if></#list>
        <#--role_id, role_name, role_create_date, info-->
    </sql>
    <select id="selectByExample" resultMap="BaseResultMap" parameterType="${entitypackagename}.${javaname}Example" >
        select
        <if test="distinct" >
            distinct
        </if>
        <include refid="Base_Column_List" />
        from ${tableEntity.tabname}
        <if test="_parameter != null" >
            <include refid="Example_Where_Clause" />
        </if>
        <if test="orderByClause != null" >
            order by ${r'${orderByClause}'}
        </if>
    </select>

    <#--继续yanj8u-->
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
            parameterType="${entitypackagename}.${javaname}">
        select
        <include refid="Base_Column_List" />
        from ${tableEntity.tabname}
        where <#list tabkeys as res>
            ${res} = ${r'#{'}${tabname_javaname_map[res]}${r'}'}<#if res_has_next= false><#else >and</#if>
        </#list>
    </select>
    <delete id="deleteByPrimaryKey" parameterType="${entitypackagename}.${javaname}">
        delete from
    ${tableEntity.tabname}
        where <#list tabkeys as res>
    ${res} = ${r'#{'}${tabname_javaname_map[res]}${r'}'}<#if res_has_next= false><#else >and</#if>
    </#list>
    </delete>
    <delete id="deleteByExample" parameterType="${entitypackagename}.${javaname}">
        delete from ${tableEntity.tabname}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
    </delete>
    <insert id="insert" parameterType="${imPackage}.${javaname}">
        insert into ${tableEntity.tabname} (
    <#list  tableEntity.columnEntitys as res>${res.COLUMN_NAME}<#if res_has_next = false><#else>,</#if></#list>
        )
        values
        (

    <#list  tableEntity.columnEntitys as res> ${r'#{'}${tabname_javaname_map[res.COLUMN_NAME]}${r'}'}<#if res_has_next = false><#else>,</#if></#list>
        )
    </insert>
    <insert id="insertSelective" parameterType="${entitypackagename}.${javaname}">
        insert into ${tableEntity.tabname}
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list  tableEntity.columnEntitys as res>
            <if test="${tabname_javaname_map[res.COLUMN_NAME]} != null">
            ${res.COLUMN_NAME},
            </if>
        </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
        <#list  tableEntity.columnEntitys as res>
            <if test="${tabname_javaname_map[res.COLUMN_NAME]} != null">
            ${r'#{'}${tabname_javaname_map[res.COLUMN_NAME]}${r'}'},
            </if>
        </#list>
        </trim>
    </insert>
    <select id="countByExample" parameterType="${entitypackagename}.${javaname}Example"
            resultType="java.lang.Integer">
        select count(*) from ${tableEntity.tabname}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update ${tableEntity.tabname}
        <set>
        <#list  tableEntity.columnEntitys as res>
            <if test="record.${tabname_javaname_map[res.COLUMN_NAME]} != null">
            ${res.COLUMN_NAME} = ${r'#{'}record.${tabname_javaname_map[res.COLUMN_NAME]}${r'}'},
            </if>
        </#list>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause" />
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update  ${tableEntity.tabname}
        set <#list  tableEntity.columnEntitys as res>
    ${res.COLUMN_NAME} = ${r'#{'}record.${tabname_javaname_map[res.COLUMN_NAME]}${r'}'}<#if res_has_next = false><#else>,</#if>
        </#list>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause" />
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="${entitypackagename}.${javaname}">
        update  ${tableEntity.tabname}
        <set>
        <#list  tableEntity.columnEntitys as res>
            <#if res.COLUMN_KEY=false>
            <if test="${tabname_javaname_map[res.COLUMN_NAME]} != null">
            ${res.COLUMN_NAME} = ${r'#{'}${tabname_javaname_map[res.COLUMN_NAME]}${r'}'}<#if res_has_next = false><#else>,</#if>
            </if>
            </#if>
        </#list>
        </set> where
    <#list tabkeys as res>
    ${res} = ${r'#{'}${tabname_javaname_map[res]}${r'}'}<#if res_has_next= false><#else >and</#if>
    </#list>
    </update>
    <update id="updateByPrimaryKey" parameterType="${entitypackagename}.${javaname}">
        update ${tableEntity.tabname}
        set
    <#list  tableEntity.columnEntitys as res>
        <#if res.COLUMN_KEY=false>
        ${res.COLUMN_NAME} = ${r'#{'}${tabname_javaname_map[res.COLUMN_NAME]}${r'}'}<#if res_has_next = false><#else>,</#if>
        </#if>
    </#list>
        where <#list tabkeys as res>
    ${res} = ${r'#{'}${tabname_javaname_map[res]}${r'}'}<#if res_has_next= false><#else >and</#if>
    </#list>
    </update>
    <!-- 通过主键集合批量删除记录 -->
    <delete id="deleteByPrimaryKeys" parameterType="java.util.List">
    <#assign i = "0">
        DELETE FROM ${tableEntity.tabname} WHERE  <#list tabkeys as res> <#if i="0">${res}<#assign i = "2"></#if></#list> in

        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">

        ${r'#{item}'}

        </foreach>

    </delete>
    <#--是否产生详细删除修改和增加的方法-->
<#if  isdetailed=true>
<#--删除的-->
    <#list tableEntity.columnEntitys as iskey>
        <#if iskey.COLUMN_KEY=false>
            <delete id="deleteBy${tabname_javaname_map[iskey.COLUMN_NAME]}" parameterType="java.util.List">
                delete from  ${tableEntity.tabname}  where ${iskey.COLUMN_NAME} in
                <foreach item="item" collection="list" open="(" separator="," close=")">
                ${r'#{item.'}${tabname_javaname_map[iskey.COLUMN_NAME]}${r'}'}
                </foreach>
            </delete>
        </#if>
        </#list>
    <#list tableEntity.columnEntitys as iskey>
    <#--修改的-->
    <update id="updateBy${tabname_javaname_map[iskey.COLUMN_NAME]}"  parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            update ${tableEntity.tabname}
            <set >
            <#list tableEntity.columnEntitys as values>
                <if test="item.${tabname_javaname_map[values.COLUMN_NAME]} != null" >
                    ${values.COLUMN_NAME} = ${r'#{item.'}${tabname_javaname_map[values.COLUMN_NAME]}${r'},'}
                </if>
            </#list>
            </set>
            where ${iskey.COLUMN_NAME} = ${r'#{item.'}${tabname_javaname_map[iskey.COLUMN_NAME]}${r'}'}
        </foreach>
    </update>
    </#list>
<#--新增的-->
    <insert id="inserts" parameterType="java.util.List">
        insert into words(
        <#list  tableEntity.columnEntitys as res>${res.COLUMN_NAME}<#if res_has_next = false><#else>,</#if></#list>
            )
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (
    <#list  tableEntity.columnEntitys as res>
            ${r'#{item.'}${tabname_javaname_map[res.COLUMN_NAME]}${r'}'}<#if res_has_next = false><#else>,</#if>
    </#list>
            )
        </foreach>
    </insert>
</#if>

</mapper>